Skip to main content

Configuring modules

7. Configuring Modules:

Configuring modules in a Linux system involves managing kernel modules or device drivers. Kernel modules are pieces of code that can be loaded and unloaded into the running kernel to add or remove functionality. These modules often interact with hardware devices or provide additional features to the kernel.

Module Management Commands:

  1. Listing Loaded Modules:

    • lsmod: This command lists all currently loaded kernel modules.

      lsmod

      Example output:

      Module                  Size  Used by
      usb_storage 69632 1
      nvidia_uvm 1003520 0
      nvidia_drm 49152 2
      nvidia_modeset 1232896 2
      nvidia 34052096 172 nvidia_uvm,nvidia_modeset
  2. Loading Modules:

    • modprobe: This command is used to load kernel modules into the running kernel.

      modprobe module_name

      Example:

      modprobe usb_storage
    • To load a module at boot time, you can add it to the /etc/modules file.

  3. Unloading Modules:

    • rmmod: This command is used to remove (unload) kernel modules from the running kernel.

      rmmod module_name

      Example:

      rmmod usb_storage

Module Configuration Files:

  1. /etc/modules:

    • This file lists kernel modules that should be loaded at boot time.

    • Edit this file to add modules that you want to load automatically at startup.

    sudo nano /etc/modules

    Example /etc/modules file:

    # /etc/modules: kernel modules to load at boot time.
    #
    # This file contains the names of kernel modules that should be loaded
    # at boot time, one per line. Lines beginning with "#" are ignored.

    usb_storage
  2. /etc/modprobe.d/ Directory:

    • The /etc/modprobe.d/ directory contains configuration files for module loading.

    • You can create custom configuration files to set options and aliases for specific modules.

    Example:

    sudo nano /etc/modprobe.d/my_module.conf

    Example my_module.conf file:

    # Configuration for my_module
    options my_module option_name=value

Module Options:

  1. Setting Module Options:

    • Some modules support options that can be configured when loading the module.

    • Use the modprobe command with the module_name option_name=value syntax to set options.

    Example:

    modprobe my_module option_name=value
  2. Persistent Module Options:

    • To set module options persistently, create a configuration file in /etc/modprobe.d/.

    • Use the format options module_name option_name=value in the configuration file.

    Example:

    sudo nano /etc/modprobe.d/my_module.conf

    Example my_module.conf file:

    # Set options for my_module
    options my_module option_name=value

Module Aliases:

  1. Module Aliases:

    • Module aliases define alternative names for modules.

    • They are used by the kernel to load modules when devices are detected.

    • Aliases are defined in /lib/modules/$(uname -r)/modules.alias and other files.

  2. Setting Module Aliases:

    • You can create custom module aliases using /etc/modprobe.d/ configuration files.

    Example:

    sudo nano /etc/modprobe.d/my_module-alias.conf

    Example my_module-alias.conf file:

    # Create an alias for my_module
    alias my_alias_module my_module